package com.neu.beilian.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.neu.beilian.domain.bo.pwdlogin_Bo;
import com.neu.beilian.domain.po.User;
import com.neu.beilian.domain.vo.pwdlogin_Vo;
import com.neu.beilian.mapper.UserMapper;
import com.neu.beilian.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 陈鲲鹏
 * @since 2025-05-07
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {


    @Override
    public pwdlogin_Vo pwdlogin(pwdlogin_Bo pwdloginBo, HttpServletRequest request) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<User>()
                .eq(User::getPhone,pwdloginBo.getPhone())
                        .eq(User::getPassword,pwdloginBo.getPassword());

        User user = getOne(queryWrapper);
        //登录成功，转换为VO，status = 0
        if(user != null){


            String sessionId = request.getSession().getId();

            pwdlogin_Vo.InnerList innerList = pwdlogin_Vo.InnerList.builder()
                    .did(user.getDid())
                    .userid(user.getUserid())
                    .nickname(user.getNickname())
                    .companyid(user.getCompanyid())
                    .loginsession(sessionId)
                    .staffstatus(2L)
                    .build();
            pwdlogin_Vo pwdloginVo = pwdlogin_Vo.builder()
                    .status(0)
                    .info(innerList)
                    .build();
            return pwdloginVo;

        }else{
            return pwdlogin_Vo.builder()
                    .status(-45935)
                    .build();
        }
    }
}
